<?
    final class Principio_Model_DictionaryMapper extends Principio_Mapper
    {
        protected static $db_table = null;
        protected static function getDbTableName() { return "Dictionary"; }



        public static function get($id = null)
        {
            try
            {
                if (!is_null($id))
                {
                    if ($id == -1)
                        return new Principio_Model_Dictionary();

                    $result = self::getDBTable()->find($id);
                    if ($result->count() != 1)
                        throw new Zend_Db_Exception("Dictionary with given ID doesn't exist");

                    return new Principio_Model_Dictionary($result[0]->toArray());
                }
                else
                {
                    $values = self::getDBTable()->fetchAll();
                    $dictionaries = array();

                    foreach ($values as $dictionary)
                        $dictionaries[] = new Principio_Model_Dictionary($dictionary->toArray());

                    return $dictionaries;
                };
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        /*
        public static function save(Principio_Model_Firmware $model_firmware)
        {
            try
            {
                self::getDBTable()->getAdapter()->beginTransaction();

                $data = array(
                                "version" => $model_firmware->getVersion(),
                                "caption" => $model_firmware->getCaption(),
                );

                if ($model_firmware->getID() == -1)
                {
                    $id = self::getDBTable()->insert($data);
                    $model_firmware->setID($id);
                }
                else
                    self::getDBTable()->update($data, array("id=?" => $model_firmware->getID()));

                self::getDBTable()->getAdapter()->commit();

                return $model_firmware->getID();
            }
            catch (Exception $ex)
            {
                self::reportException($ex);
                self::getDBTable()->getAdapter()->rollBack();

                return false;
            };
        }


        public static function delete($id, $use_transaction = true)
        {
            try
            {
                if ($use_transaction)
                    self::getDBTable()->getAdapter()->beginTransaction();

                Principio_Model_TypeMapper::resetFirmware($id);
                self::getDBTable()->delete(array("id=?" => $id));

                if ($use_transaction)
                    self::getDBTable()->getAdapter()->commit();

                return true;
            }
            catch (Exception $ex)
            {
                $return = self::reportException($ex);

                if ($use_transaction)
                {
                    self::getDBTable()->getAdapter()->rollback();
                    return false;
                }
                else
                    return $return;

            };
        }


        public static function checkUniqueCaption(Principio_Model_Firmware $model_firmware)
        {
            try
            {
                $select = self::getDBTable()->select(Zend_Db_Table_Abstract::SELECT_WITH_FROM_PART)->where("caption=?", $model_firmware->getCaption())->where("id<>?", $model_firmware->getID())->columns("id");
                return (is_null(self::getDBTable()->fetchRow($select)));
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }
*/
    }
?>